// run: $exec < input
// opt: 0
// flag: -g
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

template <
	class T,
	class COMPARE = std::less<T>
>
struct sparse_table
{
	typedef T value_type;
	typedef unsigned int size_type;
	typedef COMPARE comparer;
	typedef std::vector<value_type> vector_type;

	inline size_type log2(size_type len) const
	{
		size_type tmp = 0;
		for (; size_type(1) << tmp <= len; tmp++); // FIXME 11 neednot write size_type
		return tmp - 1;
	}

	sparse_table(comparer cmp = comparer()) : cmp(cmp) {}

	void init(vector_type const & data)
	{
		size_type n = data.size();
		size_type len = log2(n);

		for (size_type i = 0; i < n; i++) st[i][0] = i;
		for (size_type l = 1; l <= len; l++)
			for (size_type i = 0; (i + (1<<l) - 1) < n; i++)
				if (cmp(data[ st[i][l - 1] ], data[ st[i + (1<<(l-1))][l - 1] ]))
					st[i][l] = st[i][l - 1];
				else
					st[i][l] = st[i + (1 << (l-1))][l - 1];
	}

	// [l, r]
	size_type query_interval_index(vector_type const & data, size_type l, size_type r) const
	{
		if (r < l) std::swap(l, r);
		int k = log2(r - l + 1);
		if (cmp(data[ st[l][k] ], data[ st[r - (1<<k) + 1][k] ]))
			return st[l][k];
		else
			return st[r - (1<<k) + 1][k];
	}

	// [l, r]
	value_type query_interval(vector_type const & data, size_type l, size_type r) const
	{
		return data[ query_interval_index(data, l, r) ];
	}

private:
	size_type static const maxn = 100004;
	size_type static const  len = 17;
	size_type st[maxn][len];
	comparer cmp;
};


struct suffix_array
{
	typedef std::vector<int> & v_ref;
	typedef std::vector<int> const & v_cref;
	typedef std::string const & s_cref;

	struct suffix_cmp
	{
		suffix_cmp(v_cref rank, int const & gap, int const & len)
			: rank(rank), gap(gap), len(len) {}

		bool operator()(int i, int j)
		{
			if (rank[i] != rank[j]) return rank[i] < rank[j];
			return (i + gap < len && j + gap < len) ?
						(rank[i + gap] < rank[j + gap]) : i > j;
		}

	private:
		v_cref rank;
		int const & gap;
		int const & len;
	};

	suffix_array(s_cref s, v_ref sa, v_ref rank, v_ref height)
		: s(s), sa(sa), rank(rank), height(height)
	{
		tmp_rank.resize(rank.size());
	}

	void build_suffix_array()
	{
		int n = s.size();
		for (int i = 0; i < n; i++) { sa[i] = i; rank[i] = s[i]; }
		for (int gap = 1; ; gap *= 2) {
			suffix_cmp cmp(rank, gap, n);
			std::sort(sa.begin(), sa.begin() + n, cmp);
			for (int i = 0; i < n-1; i++)
				tmp_rank[i + 1] = tmp_rank[i] + cmp(sa[i], sa[i + 1]);
			for (int i = 0; i < n; i++) rank[sa[i]] = tmp_rank[i];
			if (tmp_rank[n - 1] == n - 1) break;
		}
	}

	void build_lcp()
	{
		int n = s.size();
		for (int i = 0, k = 0; i < n; i++)
			if (rank[i] != n-1) {
				for (int j = sa[rank[i] + 1]; s[i + k] == s[j + k]; k++);
				height[rank[i]] = k;
				if (k) k--;
			}
	}

	int lcp(sparse_table<int> const & st, int x, int y, int n) const
	{
		if (y >= n) return 0;
		int l = rank[x], r = rank[y];
		if (r < l) std::swap(l, r);
		return st.query_interval(height, l, r - 1);
	}

private:
	s_cref s;
	v_ref sa; // suffix array
	v_ref rank;
	v_ref height; // lcp array, longest common prefix array
	std::vector<int> tmp_rank;
};


int const maxn = 100007;

char input[maxn];
int q[maxn], tot;
int l, ansr;

void print(std::vector<int> const & sa, suffix_array const & suffix, sparse_table<int> const & st, std::string const & s)
{
	for (int i = 0; i < l; i++) {
		int tp = sa[i];
		for (int j = 0; j < tot; j++) {
			int tr = q[j];
			if (suffix.lcp(st, tp, tp + tr, l) >= (ansr - 1) * tr) {
				for (int k = 0; k < ansr * tr; k++)
					std::printf("%c", s[tp + k]);
				std::printf("\n");
				return;
			}
		}
	}
}

int main()
{
	for (int ti = 1; ; ti++) {
//		std::cin >> s;
		std::scanf("%s", input);
//		if (input[0] == '#') break;
		if (input[0] == '#') break;
		std::printf("Case %d: ", ti);
		std::string s(input);
		l = s.size();
		std::vector<int> sa(l);
		std::vector<int> rank(l);
		std::vector<int> height(l);
		suffix_array suffix(s, sa, rank, height);
		suffix.build_suffix_array();
		suffix.build_lcp();
		sparse_table<int> st;
		st.init(height);

		ansr = 1;
		q[0] = tot = 1;
		for (int i = 1; i < l; i++) {
			for (int j = 0; j + i < l; j += i) {
				int lcp = suffix.lcp(st, j, j + i, l);
				int tp = j - (i - lcp % i);
				if (tp >= 0)
					lcp = std::max(lcp, suffix.lcp(st, tp, tp + i, l));
				lcp = lcp / i + 1;
				if (lcp > ansr) {
					ansr = lcp;
					q[0] = i;
					tot = 1;
				} else if (lcp == ansr) {
					q[tot++] = i;
				}
			}
		}

		print(sa, suffix, st, s);
	}
}

